<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core">

    <ui:composition template="/template.xhtml">

        <ui:define name="title">
            <h:outputText value="#{bundle.EditClienteTitle}"></h:outputText>
        </ui:define>

        <ui:define name="menuLateral">

            <h:form id="formLateralMenuClienteEdit">
                
            </h:form>

        </ui:define>

        <ui:define name="body">

            <h:panelGroup id="messagePanel" layout="block">
                <p:growl />
            </h:panelGroup>

            <h:form id="formClienteEdit">
                <p:panelGrid columns="8" id="pgClienteEdit">
                    <h:outputLabel value="#{bundle.EditPessoaLabel_nome}" for="nome" />
                    <p:inputText id="nome" value="#{clienteController.selected.nome}" 
                                 title="#{bundle.EditPessoaTitle_nome}" required="true" 
                                 requiredMessage="#{bundle.EditPessoaRequiredMessage_nome}"/>
                    <h:outputLabel value="#{bundle.EditPessoaLabel_tipoPessoa}" for="tipoPessoa" />
                    <p:selectOneMenu id="tipoPessoa" value="#{clienteController.selected.tipoPessoa}" 
                                     label="#{bundle.EditPessoaTitle_tipoPessoa}" required="true" 
                                     requiredMessage="#{bundle.EditPessoaRequiredMessage_tipoPessoa}">
                        <f:selectItem itemLabel="Física"   itemValue="F"/>
                        <f:selectItem itemLabel="Jurídica" itemValue="J"/>
                        <p:ajax update=":cgc" listener="#{clienteController.mudarCgc}"/>
                    </p:selectOneMenu>
                    <h:outputLabel value="#{bundle.EditPessoaLabel_cgc}" for="cgc" />
                    <p:inputMask id="cgc" value="#{clienteController.selected.cgc}" 
                                 title="#{bundle.EditPessoaTitle_cgc}" required="true" 
                                 requiredMessage="#{bundle.EditPessoaRequiredMessage_cgc}"
                                 mask="#{clienteController.maskCgc}" />-->
                    <h:outputLabel value="#{bundle.EditPessoaLabel_rg}" for="rg" />
                    <p:inputText id="rg" value="#{clienteController.selected.rg}" 
                                 title="#{bundle.EditPessoaTitle_rg}" />
                    <h:outputLabel value="#{bundle.EditPessoaLabel_dataNascimento}" for="dataNascimento" />
                    <p:calendar id="dataNascimento" value="#{clienteController.selected.dataNascimento}"
                                locale="pt" title="#{bundle.EditPessoaTitle_dataNascimento}"  
                                pattern="dd/MM/yyyy" />
                    <h:outputLabel value="#{bundle.EditPessoaLabel_EMail}" for="EMail" />
                    <p:inputText id="EMail" value="#{clienteController.selected.EMail}" 
                                 title="#{bundle.EditPessoaTitle_EMail}" />
                    <h:outputLabel value="#{bundle.EditPessoaLabel_twitter}" for="twitter" />
                    <p:inputText id="twitter" value="#{clienteController.selected.twitter}" 
                                 title="#{bundle.EditPessoaTitle_twitter}" />
                    <h:outputLabel value="#{bundle.EditPessoaLabel_facebook}" for="facebook" />
                    <p:inputText id="facebook" value="#{clienteController.selected.facebook}" 
                                 title="#{bundle.EditPessoaTitle_facebook}" />
                    <h:outputLabel value=" " />
                    <h:outputLabel value=" " />
                    <h:outputLabel value=" " />
                    <p:commandButton value="#{bundle.EditPessoaSaveLink}" actionListener="#{clienteController.update}"
                                     icon="ui-icon-disk" ajax="false" />
                    <p:commandButton value="Limpar" action="#{clienteController.prepareEdit}"
                                     icon="ui-icon-document-b" ajax="false" />
                    <h:outputLabel value=" " />
                    <h:outputLabel value=" " />
                    <h:outputLabel value=" " />
                </p:panelGrid>
                <br/>
                <br/>
            </h:form>

            <h:form id="formClienteEnderecoList">
                <h:panelGroup id="pgTableEndereco">

                    <p:dataTable id="tableClienteEndereco" value="#{clienteController.itemsEndereco}"
                                 var="itemEndereco" emptyMessage="#{bundle.ListEnderecoEmpty}" style="border:solid 1px">


                        <f:facet name="header">
                            <h:outputText value="#{bundle.ListEnderecoTitle}"/>
                        </f:facet>

                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListEnderecoTitle_tipoEndereco}"/>
                            </f:facet>
                            <h:outputText value="#{itemEndereco.tipoEndereco.descricao}"/>
                        </p:column>
                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListEnderecoTitle_descricao}"/>
                            </f:facet>
                            <h:outputText value="#{itemEndereco.descricao}"/>
                        </p:column>
                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListEnderecoTitle_numero}"/>
                            </f:facet>
                            <h:outputText value="#{itemEndereco.numero}"/>
                        </p:column>
                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListEnderecoTitle_bairro}"/>
                            </f:facet>
                            <h:outputText value="#{itemEndereco.bairro}"/>
                        </p:column>
                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListEnderecoTitle_cidade}"/>
                            </f:facet>
                            <h:outputText value="#{itemEndereco.cidade.toString()}"/>
                        </p:column>
                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListEnderecoTitle_cep}"/>
                            </f:facet>
                            <h:outputText value="#{itemEndereco.cep}"/>
                        </p:column>
                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListEnderecoTitle_complemento}"/>
                            </f:facet>
                            <h:outputText value="#{itemEndereco.complemento}"/>
                        </p:column>

                        <p:column>
                            <f:facet name="header">
                                <p:commandButton actionListener="#{clienteController.prepareCreateEndereco}" 
                                                 value="#{bundle.ListEnderecoCreateLink}"
                                                 update=":formClienteEnderecoCreate:pgEnderecoCreate" 
                                                 oncomplete="dialogEnderecoCreate.show()"/>
                            </f:facet>
                            <p:commandButton actionListener="#{clienteController.prepareEditEndereco}" 
                                             value="#{bundle.ListEnderecoEditLink}"
                                             update=":formClienteEnderecoEdit:pgEnderecoEdit" 
                                             oncomplete="dialogEnderecoEdit.show()" />
                            <p:commandButton actionListener="#{clienteController.destroyEndereco}" 
                                             value="#{bundle.ListEnderecoDestroyLink}" ajax="false"/>
                        </p:column>

                    </p:dataTable>

                </h:panelGroup>
                <br/>
                <br/>
            </h:form>

            <h:form id="formClienteTelefoneList">
                <h:panelGroup id="pgTableTelefone">

                    <p:dataTable id="tableClienteTelefone" value="#{clienteController.itemsTelefone}"
                                 var="itemTelefone" emptyMessage="#{bundle.ListTelefoneEmpty}" style="border:solid 1px">


                        <f:facet name="header">
                            <h:outputText value="#{bundle.ListTelefoneTitle}"/>
                        </f:facet>

                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListTelefoneTitle_tipoTelefone}"/>
                            </f:facet>
                            <h:outputText value="#{itemTelefone.tipoTelefone.descricao}"/>
                        </p:column>
                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListTelefoneTitle_numero}"/>
                            </f:facet>
                            <h:outputText value="#{itemTelefone.numero}"/>
                        </p:column>
                        

                        <p:column>
                            <f:facet name="header">
                                <p:commandButton actionListener="#{clienteController.prepareCreateTelefone}" 
                                                 value="#{bundle.ListTelefoneCreateLink}"
                                                 update=":formClienteTelefoneCreate:pgTelefoneCreate" 
                                                 oncomplete="dialogTelefoneCreate.show()"/>
                            </f:facet>
                            <p:commandButton actionListener="#{clienteController.prepareEditTelefone}" 
                                             value="#{bundle.ListTelefoneEditLink}"
                                             update=":formClienteTelefoneEdit:pgTelefoneEdit" 
                                             oncomplete="dialogTelefoneEdit.show()" />
                            <p:commandButton actionListener="#{clienteController.destroyTelefone}" 
                                             value="#{bundle.ListTelefoneDestroyLink}" ajax="false"/>
                        </p:column>
                        
                    </p:dataTable>
                </h:panelGroup>
            </h:form>

            <h:form id="formClienteEnderecoCreate">

                <p:dialog header="Novo Endereço" widgetVar="dialogEnderecoCreate" resizable="false" 
                          modal="true" showEffect="slide">
                    <p:panelGrid id="pgEnderecoCreate" columns="2">
                        <h:outputLabel value="#{bundle.CreateEnderecoLabel_tipoEndereco}" for="tipoEndereco" />
                        <p:selectOneMenu id="tipoEndereco" 
                                         value="#{clienteController.enderecoSelected.tipoEndereco}" 
                                         label="#{bundle.CreateEnderecoTitle_tipoEndereco}" required="true" 
                                         requiredMessage="#{bundle.CreateEnderecoRequiredMessage_tipoEndereco}">
                            <f:selectItems value="#{tipoEnderecoController.itemsAvailableSelectOne}"/>
                        </p:selectOneMenu>
                        <h:outputLabel value="#{bundle.CreateEnderecoLabel_descricao}" for="descricao" />
                        <p:inputText id="descricao" value="#{clienteController.enderecoSelected.descricao}" 
                                     title="#{bundle.CreateEnderecoTitle_descricao}" required="true" 
                                     requiredMessage="#{bundle.CreateEnderecoRequiredMessage_descricao}"/>
                        <h:outputLabel value="#{bundle.CreateEnderecoLabel_numero}" for="numero" />
                        <p:inputText id="numero" value="#{clienteController.enderecoSelected.numero}" 
                                     title="#{bundle.CreateEnderecoTitle_numero}" required="true" 
                                     requiredMessage="#{bundle.CreateEnderecoRequiredMessage_numero}"/>
                        <h:outputLabel value="#{bundle.CreateEnderecoLabel_bairro}" for="bairro" />
                        <p:inputText id="bairro" value="#{clienteController.enderecoSelected.bairro}" 
                                     title="#{bundle.CreateEnderecoTitle_bairro}" required="true" 
                                     requiredMessage="#{bundle.CreateEnderecoRequiredMessage_bairro}"/>
                        <h:outputLabel value="#{bundle.CreateEnderecoLabel_cidade}" for="cidade" />
                        <p:selectOneMenu id="cidade" value="#{clienteController.enderecoSelected.cidade}" 
                                         label="#{bundle.CreateEnderecoTitle_cidade}" required="true" 
                                         requiredMessage="#{bundle.CreateEnderecoRequiredMessage_cidade}">
                            <f:selectItems value="#{cidadeController.itemsAvailableSelectOne}"/>
                        </p:selectOneMenu>
                        <h:outputLabel value="#{bundle.CreateEnderecoLabel_cep}" for="cep" />
                        <p:inputText id="cep" value="#{clienteController.enderecoSelected.cep}" 
                                     title="#{bundle.CreateEnderecoTitle_cep}" />
                        <h:outputLabel value="#{bundle.CreateEnderecoLabel_complemento}" for="complemento" />
                        <p:inputText id="complemento" value="#{clienteController.enderecoSelected.complemento}" 
                                     title="#{bundle.CreateEnderecoTitle_complemento}" />
                        <p:commandButton actionListener="#{clienteController.createEndereco}" 
                                         value="#{bundle.CreateEnderecoSaveLink}"
                                         oncomplete="dialogEnderecoCreate.hide()"
                                         ajax="false" />
                        <p:commandButton value="Limpar" type="reset" ajax="false"/>
                    </p:panelGrid>
                </p:dialog>

            </h:form>

            <h:form id="formClienteEnderecoEdit">

                <p:dialog header="Editar Endereço" widgetVar="dialogEnderecoEdit" resizable="false" 
                          modal="true" showEffect="slide">
                    <p:panelGrid id="pgEnderecoEdit" columns="2">
                        <h:outputLabel value="#{bundle.EditEnderecoLabel_tipoEndereco}" for="tipoEndereco" />
                        <p:selectOneMenu id="tipoEndereco" 
                                         value="#{clienteController.enderecoSelected.tipoEndereco}" 
                                         label="#{bundle.EditEnderecoTitle_tipoEndereco}" required="true" 
                                         requiredMessage="#{bundle.EditEnderecoRequiredMessage_tipoEndereco}">
                            <f:selectItems value="#{tipoEnderecoController.itemsAvailableSelectOne}"/>
                        </p:selectOneMenu>
                        <h:outputLabel value="#{bundle.EditEnderecoLabel_descricao}" for="descricao" />
                        <p:inputText id="descricao" value="#{clienteController.enderecoSelected.descricao}" 
                                     title="#{bundle.EditEnderecoTitle_descricao}" required="true" 
                                     requiredMessage="#{bundle.EditEnderecoRequiredMessage_descricao}"/>
                        <h:outputLabel value="#{bundle.EditEnderecoLabel_numero}" for="numero" />
                        <p:inputText id="numero" value="#{clienteController.enderecoSelected.numero}" 
                                     title="#{bundle.EditEnderecoTitle_numero}" required="true" 
                                     requiredMessage="#{bundle.EditEnderecoRequiredMessage_numero}"/>
                        <h:outputLabel value="#{bundle.EditEnderecoLabel_bairro}" for="bairro" />
                        <p:inputText id="bairro" value="#{clienteController.enderecoSelected.bairro}" 
                                     title="#{bundle.EditEnderecoTitle_bairro}" required="true" 
                                     requiredMessage="#{bundle.EditEnderecoRequiredMessage_bairro}"/>
                        <h:outputLabel value="#{bundle.EditEnderecoLabel_cidade}" for="cidade" />
                        <p:selectOneMenu id="cidade" value="#{clienteController.enderecoSelected.cidade}" 
                                         label="#{bundle.EditEnderecoTitle_cidade}" required="true" 
                                         requiredMessage="#{bundle.EditEnderecoRequiredMessage_cidade}">
                            <f:selectItems value="#{cidadeController.itemsAvailableSelectOne}"/>
                        </p:selectOneMenu>
                        <h:outputLabel value="#{bundle.EditEnderecoLabel_cep}" for="cep" />
                        <p:inputText id="cep" value="#{clienteController.enderecoSelected.cep}" 
                                     title="#{bundle.EditEnderecoTitle_cep}" />
                        <h:outputLabel value="#{bundle.EditEnderecoLabel_complemento}" for="complemento" />
                        <p:inputText id="complemento" value="#{clienteController.enderecoSelected.complemento}" 
                                     title="#{bundle.EditEnderecoTitle_complemento}" />
                        <p:commandButton actionListener="#{clienteController.updateEndereco}" 
                                         value="#{bundle.EditEnderecoSaveLink}"
                                         oncomplete="dialogEnderecoEdit.hide()"
                                         ajax="false" />
                        <p:commandButton value="Limpar" type="reset" ajax="false"/>
                    </p:panelGrid>
                </p:dialog>

            </h:form>

            <h:form id="formClienteTelefoneCreate">

                <p:dialog header="Novo Telefone" widgetVar="dialogTelefoneCreate" resizable="false" 
                          modal="true" showEffect="slide">
                    <p:panelGrid id="pgTelefoneCreate" columns="2">
                        <h:outputLabel value="#{bundle.CreateTelefoneLabel_tipoTelefone}" for="tipoTelefone" />
                        <p:selectOneMenu id="tipoTelefone" value="#{clienteController.telefoneSelected.tipoTelefone}" 
                                         label="#{bundle.CreateTelefoneTitle_tipoTelefone}" required="true" 
                                         requiredMessage="#{bundle.CreateTelefoneRequiredMessage_tipoTelefone}">
                            <f:selectItems value="#{tipoTelefoneController.itemsAvailableSelectOne}"/>
                        </p:selectOneMenu>
                        <h:outputLabel value="#{bundle.CreateTelefoneLabel_numero}" for="numero" />
                        <p:inputText id="numero" value="#{clienteController.telefoneSelected.numero}" 
                                     title="#{bundle.CreateTelefoneTitle_numero}" />
                        <p:commandButton actionListener="#{clienteController.createTelefone}" 
                                         value="#{bundle.CreateTelefoneSaveLink}"
                                         oncomplete="dialogTelefoneCreate.hide()"
                                         ajax="false" />
                        <p:commandButton value="Limpar" type="reset" ajax="false"/>
                        
                    </p:panelGrid>
                </p:dialog>
            </h:form>

            <h:form id="formClienteTelefoneEdit">

                <p:dialog header="Novo Telefone" widgetVar="dialogTelefoneEdit" resizable="false" 
                          modal="true" showEffect="slide">
                    <p:panelGrid id="pgTelefoneEdit" columns="2">
                        <h:outputLabel value="#{bundle.EditTelefoneLabel_tipoTelefone}" for="tipoTelefone" />
                        <p:selectOneMenu id="tipoTelefone" value="#{clienteController.telefoneSelected.tipoTelefone}" 
                                         label="#{bundle.EditTelefoneTitle_tipoTelefone}" required="true" 
                                         requiredMessage="#{bundle.EditTelefoneRequiredMessage_tipoTelefone}">
                            <f:selectItems value="#{tipoTelefoneController.itemsAvailableSelectOne}"/>
                        </p:selectOneMenu>
                        <h:outputLabel value="#{bundle.EditTelefoneLabel_numero}" for="numero" />
                        <p:inputText id="numero" value="#{clienteController.telefoneSelected.numero}" 
                                     title="#{bundle.EditTelefoneTitle_numero}" />
                        <p:commandButton actionListener="#{clienteController.updateTelefone}" 
                                         value="#{bundle.EditTelefoneSaveLink}"
                                         oncomplete="dialogTelefoneEdit.hide()"
                                         ajax="false" />
                        <p:commandButton value="Limpar" type="reset" ajax="false"/>
                        
                    </p:panelGrid>
                </p:dialog>
            </h:form>

        </ui:define>
    </ui:composition>

</html>
